//@author A0088498A
package unit_test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import logic.Suggestor;

import org.junit.Test;

public class TestSuggestor {

	@Test
	public void instantiationTest() {
		Suggestor suggestor = Suggestor.getInstance();

		// Ensure lazy instantiation works
		assertFalse(suggestor == null);
	}

	@Test
	public void nullTest() {
		Suggestor suggestor = Suggestor.getInstance();
		ArrayList<String> suggestion;

		// Null string
		suggestion = suggestor.suggest(null);
		assertEquals(suggestion.size(), 0);
	}

	@Test
	public void emptyStringTest() {
		Suggestor suggestor = Suggestor.getInstance();
		ArrayList<String> suggestion;

		// Empty string, check the storage lazy instantiation works
		suggestion = suggestor.suggest("");
		assertTrue(suggestion.size() == 0);
	}

	@Test
	public void keywordSuggestTest() {
		Suggestor suggestor = Suggestor.getInstance();
		ArrayList<String> suggestion;

		suggestion = suggestor.suggest("-");
		assertTrue(suggestion.size() == 13);
	}

	@Test
	public void longerStringTest() {
		Suggestor suggestor = Suggestor.getInstance();
		ArrayList<String> suggestion;

		suggestion = suggestor.suggest("-d");
		assertTrue(suggestion.size() == 2);
		for (String s : suggestion) {
			assertTrue(s.startsWith("d"));
		}
	}

	@Test
	public void littleLongerStringTest() {
		Suggestor suggestor = Suggestor.getInstance();
		ArrayList<String> suggestion;

		suggestion = suggestor.suggest("-de");
		assertTrue(suggestion.size() == 1);
		for (String s : suggestion) {
			assertTrue(s.startsWith("de"));
		}
	}

	@Test
	public void littleMoreLongerStringTest() {
		Suggestor suggestor = Suggestor.getInstance();
		ArrayList<String> suggestion;

		suggestion = suggestor.suggest("-deq");
		assertTrue(suggestion.size() == 0);
	}

	@Test
	public void stringNotInDataTest() {
		Suggestor suggestor = Suggestor.getInstance();
		ArrayList<String> suggestion;

		suggestion = suggestor.suggest("-w");
		assertTrue(suggestion.size() == 0);
	}
}
